package com.yidian.controller;

import com.yidian.common.entity.Result;
import com.yidian.entity.Article;
import com.yidian.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * @author Superhero
 * @date 2021/12/18 12:55
 */
@RestController
@RequestMapping("/search")
@Api(value = "/search", tags = "搜索接口")
public class SearchController {

    @Autowired
    private ArticleService articleService;

    /**
     * 文章搜索
     * @param keyword
     * @return
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    @ApiOperation(value = "文章搜索", notes = "文章搜索", httpMethod = "GET", response = Result.class)
    public Result<List<Article>> search(@RequestParam String keyword) {
        List<Article> articles = articleService.search(new String(keyword.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
        return Result.ok(articles);
    }

//
//    public Result history() {
//
//    }

}
